package com.shumei.servlet.productservlet;

import com.shumei.DAO.ProductDAO;
import com.shumei.DAO.impl.ProductDAOImpl;
import com.shumei.pojo.Product;
import com.shumei.servlet.ViewBaseServlet;
import com.shumei.util.Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/productdetail")
public class MProductDetailServlet extends ViewBaseServlet {
    private ProductDAO productDAO = new ProductDAOImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pid = req.getParameter("pid");
        if (Util.isEmpty(pid)) {
            throw new RuntimeException("字符串为空串！！！");
        }
        Product product = productDAO.getProductByPid(Integer.valueOf(pid));
        req.setAttribute("product",product);
        // 将请求转发到edit视图上
        super.processTemplate("/admin/detail",req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}